<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserPointsDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserPointsDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserPointsDetail(['user:id,avatar,nickname']), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->column('id')->sortable();
            $grid->column('user.avatar','用户头像')->image('',80,80);
            $grid->column('user.nickname','用户昵称');
            $grid->column('change_type')
                 ->using([1 => '增加',2 => '减少'])
                 ->label([1 => 'success',2 => 'danger']);
            $grid->column('points');
            $grid->column('remark');
            $grid->column('change_time');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('user.nickname','用户昵称')->width(3);
                $filter->equal('change_type')
                       ->select([1 => '增加',2 => '减少'])
                       ->width(3);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserPointsDetail(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('change_type');
            $show->field('points');
            $show->field('remark');
            $show->field('change_time');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserPointsDetail(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('change_type');
            $form->text('points');
            $form->text('remark');
            $form->text('change_time');
        });
    }
}
